package org.groovyflow.util


class ComplexRuleTest extends GroovyTestCase{
  //Don't forget to see if we can get rid of ClosureInvoker in ComplexRule and DecisionTest
  def returned = "yes"
  MockContext mockContext = new MockContext()

  public void testAndFalse(){
    assert null == new ComplexRule([{x < 5}, {x < 2}], {"yes"}, "AND").setPredicateDelegate(mockContext).eval()
  }

  public void testOrTrue(){
    assert returned == new ComplexRule([{x < 5}, {x < 2}], {returned}, "OR").setPredicateDelegate(mockContext).eval()
  }

  public void testAndTrue(){
    assert returned == new ComplexRule([{x < 5}, {x > 2}], {returned}, "AND").setPredicateDelegate(mockContext).eval()
  }

  public void testOrFalse(){
    assert null == new ComplexRule([{x < 1}, {x < 0}], {returned}, "OR").setPredicateDelegate(mockContext).eval()
  }

  public void testLongAndTrue(){
    assert returned == new ComplexRule([{x < 5}, {x > 2}, {x < 4}, {x < 100}], {returned}, "AND").setPredicateDelegate(mockContext).eval()
  }

  public void testLongAndFalse(){
    assert null == new ComplexRule([{x < 5}, {x > 2}, {x < 4}, {x < 1}], {returned}, "AND").setPredicateDelegate(mockContext).eval()
  }


}

class MockContext{
  def x = 3
}